﻿using RestApp.BusinessLogic.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;

namespace RestApp.BusinessLogic
{
	public class WorkGraphicLogic : BaseLogic<WorkGraphic>, IWorkGraphicLogic
	{
        public IEnumerable<WorkGraphic> GetByUserId(int idUser)
        {
            using(var context = new RestAppEntities())
            {
                return context
                    .WorkGraphics
					.Include(t => t.FactOfWorks)
                    .Where(t => t.IdUser == idUser)
                    .ToList();
            }
        }

        public bool IfEventExists(int year, int mont, int day, int idUser)
        {
            using(var context = new RestAppEntities())
            {
                var item = context
                    .WorkGraphics
					.Include(t => t.FactOfWorks)
                    .FirstOrDefault(t => t.Year.Value == year
                        && t.Month == mont
                        && t.Day == day
                        && t.IdUser == idUser);

                return item != null;
            }
        }
    }
}
